<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
class Lienhe extends MX_Controller {
 
  var $_table = 'lienhe';
  
  function __construct(){
      parent::__construct();
      $this->load->model ( 'lienhe_model' );
  }
  
  function listlienhe(){
    $data ['list'] = $this->lienhe_model->getlienhe();
	$data ['content'] = 'admin/list';
	$this->load->view ( 'back_end/index', $data );
  }
  
  function form_add(){
  $data ['content'] = 'admin/form_add';
  $this->load->view ( 'back_end/index', $data );
  }
  
  function do_add() {
    if ($this->input->post ()) {
			$data = array ();
			$data ['ten'] = ( string ) $this->input->post ( 'ten' );
			$data ['so_dien_thoai'] = ( string ) $this->input->post ( 'so_dien_thoai' );
			$data ['yahoo'] = ( string ) $this->input->post ( 'yahoo' );
			$data ['skype'] = ( string ) $this->input->post ( 'skype' );
			$this->lienhe_model->saveItem ( 'lienhe', array ('field' => 'id', 'id' => 0 ), $data );
			redirect ( 'admin/lienhe/listlienhe' );
		}
  }
  
  function form_sua(){
       $id = ($this->uri->segment ( 4 ) == '') ? 0 : $this->uri->segment ( 4 );
	   $data ['dulieu'] = $this->lienhe_model->lay_dulieu_de_sua( $id );
		$data ['content'] = 'admin/form_sua';
		$this->load->view ( 'back_end/index', $data );
  
  }
  
  function do_sua() {
	
	  if ($this->input->post ()) {
			$id = $this->input->post ( 'id_de_sua' );
			$data ['ten'] = ( string ) $this->input->post ( 'ten' );
			$data ['so_dien_thoai'] = ( string ) $this->input->post ( 'so_dien_thoai' );
			$data ['yahoo'] = ( string ) $this->input->post ( 'yahoo' );
			$data ['skype'] = ( string ) $this->input->post ( 'skype' );
			$this->lienhe_model->saveItem ( 'lienhe', array ('field' => 'id', 'id' => $id ), $data );
			redirect ( 'admin/lienhe/listlienhe' );
		}
	}
	
  function xoa(){
        $id = ($this->uri->segment ( 4 ) == '') ? 0 : $this->uri->segment ( 4 );
		$this->lienhe_model->del ( $id );
		redirect ( 'admin/lienhe/listlienhe' );
  }	

}